package com.clstu.exception_;

import java.util.Scanner;

public class TryCatchExcercise {
    public static void main(String[] args) {
          Method md=new Method();
          md.method();
          md.method01();
    }
}
class Method{
    Scanner sc=new Scanner(System.in);
    public void method(){
        try {
            System.out.println("请输入一个整数");
            int num=Integer.parseInt(sc.next());
            System.out.println("num="+num);
        } catch (NumberFormatException e) {
            System.out.println("这不是一个整数");
            method();
        }
    }

    public void method01(){
        int num;
        do{
            try {
                System.out.println("请输入一个整数");
                num = Integer.parseInt(sc.next());
                System.out.println("num=" + num);
                break;
            } catch (NumberFormatException e) {
                System.out.println("你输入的不是一个整数");
            }
        }while(true);
    }
}